# coding: utf-8
from classes.stol import getColor, usa_combinations

combination = list()

input_string = raw_input("Введи число и цвет. Например, 16r: \n")

combination.append(int(input_string[:-1]))
combination.append(input_string[-1])
#combination = [16, "r"]

type_of_binds = ["number", "part/12", "color", "1cl", "odd", "half", "tAt", "3-row", "4numbers", "1st5", "6s"]

def getODD(x):

    if not isinstance(x, str) and x % 2 is 0:
        return x

def function(combination):

    b_number = combination[0]
    b_color = combination[1]

    bindIng = [
        [0, "00"],
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9],
        [10, 11, 12],
        [13, 14, 15],
        [16, 17, 18],
        [19, 20, 21],
        [22, 23, 24],
        [25, 26, 27],
        [28, 29, 30],
        [31, 32, 33],
        [34, 35, 36]
        ]

    bindState = dict()
    # FOR 3-row
    for bindList in bindIng:
        if b_number in bindList:
            bindState["3-row"] = bindList
            break
    # FOR column
    index = bindState["3-row"].index(b_number)
    columnArray = []

    for cl in bindIng[1:]:
        columnArray.append(cl[index])

    bindState["1cl"] = columnArray

    # 1/12
    from math import ceil

    listIndex = bindIng.index(bindState["3-row"])
    index12 = int(ceil(listIndex / 4.0))

    granicy_sreza = [index12 * 4, index12 * 4 - 3]

    #bindState["part/12"] = bindIng[granicy_sreza[1]:granicy_sreza[0] + 1]
    bindState["part/12"] = index12
    # HALF

    indexhalf = int(ceil(listIndex / 6.0))

    #bindState["half"] = bindIng[indexhalf*6 - 5:indexhalf*6 + 1]
    bindState["half"] = "first" if indexhalf is 1 else "second"

    # tAt
    tatList = list()

    try:
        if bindIng[1:].index(bindState["3-row"]) != 0:
            predListElement = bindIng[1:][bindIng[1:].index(bindState["3-row"]) - 1][index]
            tatList.append(predListElement)
    except:
        pass

    #tatList.append(b_number)
    if index < 2:
        tatList.append(bindState["3-row"][index+1])

    if index > 0:
        tatList.append(bindState["3-row"][index-1])

    try:
        sledListElement = bindIng[bindIng.index(bindState["3-row"]) + 1][index]
        tatList.append(sledListElement)
    except:
        pass


    bindState["tAt"] = sorted(tatList)

    # ODD
    # lits's generator of odd numbers
    oddList = [(x + 1) * 2 for x in range(18)]

    if b_number in oddList:
        bindState["odd"] = True
    else:
        bindState["odd"] = False


    # color:
    sOdnimCvetom = list()

    for el in usa_combinations:
        if b_color == getColor(el):
            sOdnimCvetom.append(el)

    bindState["color"] = sorted(sOdnimCvetom)

    # 4 numbers
    nynesh3List = bindState["3-row"]
    predListIndex = bindIng.index(nynesh3List) - 1
    sledListIndex = bindIng.index(nynesh3List) + 1

    if predListIndex > 0:

        if sledListIndex < 13:
            if not index:
                uzel1 = bindIng[predListIndex][index]
                uzel2 = bindIng[sledListIndex][index+1]
            elif index == 2:
                uzel1 = bindIng[predListIndex][index-1]
                uzel2 = bindIng[sledListIndex][index]
            else:
                uzel1 = bindIng[predListIndex][index-1]
                uzel2 = bindIng[sledListIndex][index+1]
        else:
            if not index:
                uzel1 = bindIng[predListIndex][index]
                uzel2 = nynesh3List[index+1]
            elif index == 2:
                uzel1 = bindIng[predListIndex][index-1]
                uzel2 = nynesh3List[index]
            else:
                uzel1 = bindIng[predListIndex][index-1]
                uzel2 = nynesh3List[index+1]
    else:
        # первый лист 1 2 3
        if not index:
            uzel1 = nynesh3List[index]
            uzel2 = bindIng[sledListIndex][index+1]
        elif index == 2:
            uzel1 = nynesh3List[index-1]
            uzel2 = bindIng[sledListIndex][index]
        else:
            uzel1 = nynesh3List[index-1]
            uzel2 = bindIng[sledListIndex][index+1]
#    print "uzel 1 = %s" % uzel1
#    print "uzel 2 = %s" % uzel2

    # Crop on squares of lists:
    # [1, 2, 4, 5] if 2

    result4square = list()
    otpravnayato4ka = uzel1

    while True:
        square = list()
        square.append(otpravnayato4ka)
        square.append(otpravnayato4ka+1)
        square.append(otpravnayato4ka+1+2)
        square.append(otpravnayato4ka+1+2+1)

        if b_number in square:
            result4square.append(square)
        #print square

        otpravnayato4ka += 1
        if otpravnayato4ka % 3 == 0:
            otpravnayato4ka += 1

        if uzel2 in square:
            break

    bindState["4numbers"] = result4square
    # 1st5
    firstList = bindIng[0]
    secondList = bindIng[1]

    if b_number in firstList or b_number in secondList:
        bindState["1st5"] = True
    else:
        bindState["1st5"] = False

    # 6s
    sixList = list()



    try:
        posledList = bindIng[sledListIndex]
    except:
        posledList = False


    if not predListIndex:
        sixList.append(nynesh3List + posledList)
    else:
        sixList.append(bindIng[predListIndex] + nynesh3List)
        if posledList:
            sixList.append(nynesh3List + posledList)
    bindState["6s"] = sixList

    return bindState

data = function(combination)


for key in data:
    print "{0} = {1}".format(key, data[key])